var prefix = ctx + "module/workFlowApply"

$(function() {
	var columns = [{
            checkbox: true
        },
				{
			field : 'applyId', 
			title : '主键' 
		},
				{
			field : 'user.userName', 
			title : '申请人' 
		},
				{
			field : 'workFlow.flowName', 
			title : '申请的流程类型' 
		},
				{
			field : 'createTime', 
			title : '申请时间' 
		},
				{
			field : 'status', 
			title : '状态' ,
			formatter: function(value, row, index) {
                if (value == 'ing') {
                	return '<span class="label label-primary">审批中</span>';
                }else if(value == 'reject'){
                	return '<span class="label label-danger">审核被拒</span>';
                }else if(value == 'pass'){
                	return '<span class="label label-success">审核通过</span>';
                }else{
                	return '<span class="label label-warning">未知</span>';
                }
            }
		},
				{
			field : 'note', 
			title : '备注' 
		},
		        {
            title: '操作',
            align: 'center',
            formatter: function(value, row, index) {
            	var actions = [];
				actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.applyId + '\')"><i class="fa fa-edit"></i></a> ');
				actions.push('<a class="btn btn-warning btn-sm ' + removeFlag + '" href="#" title="删除" onclick="remove(\'' + row.applyId + '\')"><i class="fa fa-remove"></i></a>');
				actions.push('<a class="btn btn-warning btn-sm ' + flowCheck + '" href="#" title="查看进度" onclick="flowCheckfun(\'' + row.businessId + '\')"><i class="fa fa-hand-paper-o"></i></a>');
				return actions.join('');
            }
        }];
	
	//var type=document.getElementById("type_hidden").value;  
	
	//var url = prefix + "/list?type="+type;
	var url = prefix + "/list";
	$.initTable(columns, url);
});

/*审批申请-新增*/
function add() {
    var url = prefix + '/add';
    layer_showAuto("新增审批申请", url);
}

/*审批申请-修改*/
function edit(applyId) {
    var url = prefix + '/edit/' + applyId;
    layer_showAuto("修改审批申请", url);
}

// 单条删除
function remove(applyId) {
	$.modalConfirm("确定要删除选中审批申请吗？", function() {
		_ajax(prefix + "/remove/" + applyId, "", "post");
    })
}

//查看我的审批进度
function flowCheckfun(businessId){
	 var url = prefix + '/getProcess/' + businessId;
	 layer_showAuto("查看审批进度", url);
}

// 批量删除
function batchRemove() {
	var rows = $.getSelections("applyId");
	if (rows.length == 0) {
		$.modalMsg("请选择要删除的数据", "warning");
		return;
	}
	$.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
		_ajax(prefix + '/batchRemove', { "ids": rows }, "post");
	});
}
